package yijy.company.singletonExample;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by yijy on 2017/6/14.
 * 用map实现查询字符串中出现字符最多的字符
 */
public class example {

    public static void main(String[] args) {
        String s = "1234234123412341";
//        new example().test1(s);
        System.out.println(SingletonDoubleSafeModel.getInstance1());
//        new example().equalsTest();
    }

    public void test1(String s){
        String[] arr = new String[s.length()];
        Map<String,Integer> map = new HashMap<String,Integer>();
        int maxValue=0;
        String maxKey="";
        if(s!=null){
            arr = s.split("");
            System.out.println(arr);
            for(int i=0;i<arr.length;i++){
                if(map.containsKey(arr[i])){
                    int k = map.get(arr[i]);
                    map.put(arr[i],k+1);
                }else{
                    map.put(arr[i],1);
                }
            }
        }

        Iterator it = map.entrySet().iterator();//将map的键值对通过迭代器赋给it
        while (it.hasNext()){
            Map.Entry<String,Integer> e = (Map.Entry)it.next();
            if(e.getValue()>maxValue){
                maxValue = e.getValue();
                maxKey = e.getKey();
            }
        }

        System.out.println("字符："+maxKey+";重复次数："+maxValue);
    }

    public void equalsTest(){
        String a="h";
        String b="h";
        String c = new String("h");
        System.out.println(a==b);
        System.out.println(a.equals(b));
        System.out.println(a==c);
        System.out.println(a.equals(c));
    }
}
